$(document).ready(function() {
    $('.sendsms').click(function(){
        var text=$('#inputPhonel3').val();
        //发送验证码
        $.post('/sendsms',{"phone":text},function(data){
            $('#inputCode3').attr('sms',data);
            console.log(data);
            timereturn();
            //验证码倒计时
            function timereturn() {
                var timedown = 60;
                if(si)clearInterval(si);
                var si = setInterval(function() {
                    timedown--;
                    $('.sendsms').attr("disabled","disabled");
                    $('.sendsms').css("background-color","#bdc1c1");
                    $('.sendsms').css("color","#000");
                    $('.sendsms').css("border","#bdc1c1 solid 1px");
                    $('.sendsms').val("重新获取(" + timedown + ")");

                    if (timedown == 0) {
                        $('.sendsms').attr("disabled",false);
                        $('.sendsms').css("background-color","#00CCFF");
                        $('.sendsms').css("color","#fff");
                        $('.sendsms').css("border","#00CCFF solid 1px");
                        $('.sendsms').val("重新获取");
                        clearInterval(si);
                    }
                }, 1000);
            }
        });
    });
});
//手机号验证
function phone(){
    var partten = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
    var text=$('#inputPhonel3').val();
    if(text==""||text==null){
        $('.phone-validation').text('请输入手机号码');
        $('.phone-validation').css('display','block');
        $('.phone-validation').attr('validation','false');
        $('.sendsms').attr("disabled","disabled");
        $('.sendsms').css("background-color","#bdc1c1");
        $('.sendsms').css("color","#000");
        $('.sendsms').css("border","#bdc1c1 solid 1px");
    }else if(!partten.test(text)){
        $('.phone-validation').text('请正确输入手机号码');
        $('.phone-validation').css('display','block');
        $('.phone-validation').attr('validation','false');
        $('.sendsms').attr("disabled","disabled");
        $('.sendsms').css("background-color","#bdc1c1");
        $('.sendsms').css("color","#000");
        $('.sendsms').css("border","#bdc1c1 solid 1px");
    }else{
        $('.sendsms').attr("disabled",false);
        $('.phone-validation').attr('validation','true');
        $('.sendsms').css("background-color","#00CCFF");
        $('.sendsms').css("color","#fff");
        $('.sendsms').css("border","#00CCFF solid 1px");
        $('.phone-validation').css('display','none');
    }
}
//密码验证
function pwd(){
    var text=$('#inputPassword3').val();
    if(text==""||text==null){
        $('.pwd-validation').attr('validation','false');
        $('.pwd-validation').text('请输入密码');
        $('.pwd-validation').css('display','block');
    }else if(text.length<6||text.length>16){
        $('.pwd-validation').attr('validation','false');
        $('.pwd-validation').text('请输入6~16位密码');
        $('.pwd-validation').css('display','block');
    }else{
        $('.pwd-validation').attr('validation','true');
        $('.pwd-validation').css('display','none');
    }
}
//验证码验证
function Code(){
    var partten=/^\d{6}$/;
    var text=$('#inputCode3').val();
    if(text==""||text==null){
        $('.code-validation').attr('validation',"false");
        $('.code-validation').text('请输入验证码');
        $('.code-validation').css('display','block');
    }else if(!partten.test(text)){
        $('.code-validation').attr('validation',"false");
        $('.code-validation').text('请输入正确验证码');
        $('.code-validation').css('display','block');
    }else{
        $('.code-validation').attr('validation',"true");
        $('.code-validation').css('display','none');
    }
}
//表单提交验证
function sub(){
    var text=$('#inputCode3').val();
    var code=$('.code-validation').attr('validation');
    var phone=$('.phone-validation').attr('validation');
    var pwd=$('.pwd-validation').attr('validation');
    var sms=$('#inputCode3').attr('sms');
    if(code=="true"&&phone=="true"&&pwd=="true"){
        if(text==sms){
            return true;
        }else{
            $('.code-validation').attr('validation',"false");
            $('.code-validation').text('验证码错误');
            $('.code-validation').css('display','block');
            return false;
        }
    }else{
        $('.submit-validation').css('display','block');
        $('.btn-default:hover').css("background-color"," rgb(0, 204, 255)");
        $('.btn-default:hover').css("color","#fff");
        return false;
    }
}
//鼠标焦点隐藏提交错误提示
function subvalidation(){
    $('.submit-validation').css('display','none');
}
